﻿namespace EasyWeb.Validation
{
    using System;
    using System.Globalization;

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
    public class EWValueCompareValidationAttribute : EWCompareValidationAttribute
    {
        public EWValueCompareValidationAttribute(object valueToCompare, EWCompareMode mode)
            : base(mode)
        {
            this.ValueToCompare = valueToCompare;
        }

        public object ValueToCompare { get; private set; }

        public override string FormatErrorMessage(string name)
        {
            return string.Format(CultureInfo.CurrentCulture, this.MessageTemplate, name, this.ValueToCompare);
        }

        public override bool IsValid(object value)
        {
            return Compare(value, this.ValueToCompare);
        }
    }
}
